<template>
  <div>
    <!-- table区域-begin -->
    <a-table
      ref="table"
      size="middle"
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :loading="loading"
      :pagination="false"
      @change="handleTableChange"
      :customRow="clickThenCheck">

      <span slot="action" slot-scope="text, record">
        <template v-if="record.endTime&&record.endTime!=''">
          <a  @click="showHistory(record)" >
              历史
          </a>
        </template>
        <template v-else>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
                <a-menu-item  @click="taskNotify(record)">催办</a-menu-item>
                <a-menu-item >
                  <a-popconfirm title="确定要作废流程吗?" @confirm="() => invalidProcess(record)">
                    <a>
                      作废流程
                    </a>
                  </a-popconfirm>
                </a-menu-item>
                <a-menu-item >
                  <a-popconfirm title="确定要取回流程吗?" @confirm="() => callBackProcess(record)">
                    <a>
                      取回流程
                    </a>
                  </a-popconfirm>
                </a-menu-item>
                <a-menu-item  @click="showHistory(record)">历史</a-menu-item>
            </a-menu>
          </a-dropdown>
        </template>
      </span>

      <!-- 字符串超长截取省略号显示-->
      <span slot="bpmBizTitle" slot-scope="text, record">
        <a-icon
          title="催办提醒"
          v-if="record.taskUrge"
          theme="twoTone"
          twoToneColor="#eb2f96"
          @click="taskNotify(record)"
          type="notification"/>
        <j-ellipsis :value="text" :length="15"/>
      </span>

    </a-table>

    <!-- 弹出框 -->
    <his-task-deal-modal ref="taskDealModal" :path="path" :formData="formData"></his-task-deal-modal>
    <task-notify-modal ref="taskNotifyModal"></task-notify-modal>
  </div>
</template>

<script>
  import { filterObj } from '@/utils/util'
  import { deleteAction, getAction, postAction, putAction } from '@/api/manage'
  import JEllipsis from '@/components/jeecg/JEllipsis'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { BpmNodeInfoMixin } from '@/views/modules/bpm/mixins/BpmNodeInfoMixin'
  import HisTaskDealModal from '@/views/modules/bpm/task/HisTaskDealModal';
  import TaskDealModal from '@/views/modules/bpm/task/TaskDealModal';
  import TaskNotifyModal from "@views/modules/extbpm/process/TaskNotifyModal";
  export default {
    name: 'MyRunningTaskList',
    mixins: [JeecgListMixin, BpmNodeInfoMixin],
    components: {
      HisTaskDealModal,
      TaskDealModal,
      JEllipsis,
      TaskNotifyModal
    },
    data () {
      return {
        description: '我的任务',
        // 查询条件
        queryParam: {},
        /* 分页参数 */
        ipagination: {
          current: 1,
          pageSize: 6,
          total: 10
        },
        model: {
          userName: ''
        },
        // 表头
        columns: [
          {
            title: '业务标题',
            dataIndex: 'bpmBizTitle',
            scopedSlots: { customRender: 'bpmBizTitle' }
          }, {
            title: '流程名称',
            dataIndex: 'prcocessDefinitionName'
          }, {
            title: '开始时间',
            dataIndex: 'startTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            fixed: 'right',
            align: 'center',
            width:80,
            scopedSlots: {customRender: 'action'}
          }
        ],
        path: 'modules/bpm/task/form/FormLoading',
        formData: {},
        url: {
          list: '/api/erpmng/act/task/myApplyProcessList',
          invalidProcess:"/api/erpmng/act/task/invalidProcess",
          callBackProcess:"/api/erpmng/act/task/callBackProcess",
        },
        taskId: ''
      }
    },
    methods: {
      clickThenCheck(record) {
        return {
          on: {
            click: () => {
              this.getHisProcessNodeInfo(record);
            }
          }
        };
      },
      handleOk() {
        this.loadData();
        this.$emit('ok');
      },
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        // 加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();// 查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      },
      // 流程作废
      invalidProcess(record) {
        var that = this;
        var params = {
          processInstanceId:record.processInstanceId
        };//查询条件
        putAction(that.url.invalidProcess, params).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
            that.loadData();
          }
        })
      },
      // 流程取回
      callBackProcess(record) {
        var that = this;
        var params = {
          processInstanceId:record.processInstanceId
        };//查询条件
        putAction(that.url.callBackProcess, params).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
            that.loadData();
          }
        })
      },
      // 历史
      showHistory(record){
        this.getHisProcessNodeInfo(record);
      },
      //催办
      taskNotify(record){
        this.$refs.taskNotifyModal.notify(record);
        this.$refs.taskNotifyModal.title="催办提醒";
      },
    }
  }
</script>
<style lang="less" scoped>
  /** Button按钮间距 */
  .ant-btn {
    margin-left: 3px
  }
</style>
